#/bin/sh

CC      := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc
LD      := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-ld
AR      := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-ar
OBJCOPY := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-objcopy
OBJDUMP := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-objdump

INCLUDEDIR 	:= $(shell pwd)/include \
               -I$(shell pwd)/board/tq2416 \
               -I$(shell pwd)/fs
CFLAGS 		:= -Wall -Os -fno-builtin -nostdlib
CPPFLAGS   	:= -I$(INCLUDEDIR)
LDFLAGS 		:= -L /opt/CodeSourcery/Sourcery_G++_Lite/lib/gcc/arm-none-linux-gnueabi/4.5.2/armv4t -lgcc

export 	CC AR LD OBJCOPY OBJDUMP INCLUDEDIR CFLAGS CPPFLAGS

objs := arch/arm/kernel/arm926ej.o \
        arch/arm/kernel/context.o \
        arch/arm/kernel/os_cpu_a.o \
        arch/arm/kernel/trap.o \
        arch/arm/kernel/mmu.o \
        arch/arm/kernel/nand_bootcp.o \
        arch/arm/lib/div64.o \
        kern/heap.o \
        kern/memory.o \
        kern/init.o \
        kern/sys_do.o \
        kern/ipc.o \
        kern/task.o \
        kern/workqueue.o \
        kern/kern.o \
        libc/stdio/vsprinf.o \
        libc/stdio/sprintf.o \
        libc/string.o \
        libc/syscall.o \
        libc/libc_fix.o \
        board/tq2416/s3c2416.o \
        board/tq2416/tq2416.o \
        board/tq2416/s3c2416_usbdev.o \
        board/tq2416/s3c2416_stop.o \
        board/tq2416/s3c2416_clock.o \
        board/tq2416/s3c2416_int.o \
        board/tq2416/s3c2416_ddram.o \
        board/tq2416/s3c2416_uart0.o \
        board/tq2416/s3c2416_nand.o \
        board/tq2416/s3c2416_hsmmc1.o \
        board/tq2416/hs_mmc_csdn.o \
        board/tq2416/hs1_mmc_linux.o \
        board/tq2416/sdhost.o \
        board/tq2416/s3c2416_timer4.o \
        board/tq2416/s3c2416_key.o \
        board/tq2416/s3c2416_i2c.o \
        board/tq2416/s3c2416_spi.o \
        board/tq2416/s3c2416_dm9000.o \
        board/tq2416/hs1_mmc.o
        
all: simple.elf simple.bin simple.dis brust

simple.elf: $(objs)
	${LD} -Tsimple.lds  $^ $(LDFLAGS) -o simple.elf

simple.dis:simple.elf
	${OBJDUMP} -D simple.elf > simple.dis

simple.bin: simple.elf
	${OBJCOPY} -O binary -S simple.elf $@

brust: simple.bin
	rm /mnt/hgfs/Image/u-boot.bin -rf
	cp simple.bin /mnt/hgfs/Image/u-boot.bin -rf
	
%.o:%.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

%.o:%.S
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

clean:
	rm -f *.bin *.elf *.dis *.o *~ $(objs)
	
install:simple.bin
	
	cp *.bin /mnt/hgfs/Image/u-boot.bin
